<template>
  <div class="logs">
    <el-form ref="searchForm" :inline="true" :model="searchMap" class="item">
      <el-form-item class="items" prop="operator">
        <el-input v-model="searchMap.peoples" placeholder="员工姓名"></el-input>
      </el-form-item>

      <el-form-item class="itemss" prop="value2">
        <el-date-picker
          class="itemsss"
          v-model="searchMap.value2"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right"
        >
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <button type="primary" @click="fetchData" class="buttons1">查询</button>
        <button @click="resetForm('searchForm')" class="buttons2">重置</button>
      </el-form-item>
    </el-form>

    <el-table
      :data="list"
      border
      stripe
      style="width: 100%; font-size: 2px; height: 100%;"
      :cell-style="{ padding: '0px' }"
      :row-style="{ height: '36px' }"
      @row-click="lookMessage"
    >
      <el-table-column type="index" label="序号" width="60"> </el-table-column>
      <el-table-column prop="modules" label="操作模块"> </el-table-column>
      <el-table-column prop="types" label="操作行为"></el-table-column>
      <el-table-column prop="operator" label="行为人"></el-table-column>
      <el-table-column prop="url" label="访问接口"> </el-table-column>
      <el-table-column prop="ip" label="请求IP"></el-table-column>
      <el-table-column prop="times" label="访问时间">
      </el-table-column>
    </el-table>

    <el-drawer
      title="详细信息"
      :visible.sync="drawer"
      :direction="direction"
      :size="'32%'"
      :destroy-on-close="true"
      :before-close="handleClose"
    >
      <div>
        <div style="padding: 6px 10px 6px 12px">
          <span>code:</span>
          <span style="padding-left: 10px">{{user.numbers}}</span>
        </div>
        <div style="padding: 6px 10px 6px 12px">
          <span>请求参数:</span>
          <span style="padding-left: 10px">{{user.args1}}</span>
        </div>
        <div style="padding: 6px 10px 6px 12px">
          <span>返回值:</span>
          <span style="padding-left: 10px">{{user.args2}}</span>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import logsApi from "@/api/logs";

export default {
  data() {
    return {
      list: [],
      searchMap: {
        operator: "",
        value2: "",
      },
      user:{
        numbers:"",
        args1:"",
        args2:""
      },
      direction: "ttb",
      drawer: false,
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    fetchData() {
      logsApi.search(this.searchMap).then((response) => {
        this.list = response.data;
      });
    },
    lookMessage(row){
      this.user.numbers = row.numbers
      this.user.args1 = row.args1
      this.user.args2 = row.args2
      return (this.drawer = true);
    },
    resetForm(fromName) {
      this.$refs[fromName].resetFields();
      this.fetchData();
    },
    handleClose(done) {
      done();
    }
  },
};
</script>
<style scoped>
.item {
  height: 46px;
  padding-top: 4px;
}
.items {
  padding-left: 5%;
  width: 150px;
}
.buttons1 {
  width:50px;
  height: 30px;
  margin-right: 5px;
  background: #409eff;
  border-radius: 4px;
  border: white;
}
.buttons2 {
  width:50px;
  height: 30px;
  margin-right: 5px;
  border-radius: 4px;
  background: #a5ada6;
  border: white;
}
.logs{
  width: 98%;
  margin: 0 auto;
}


</style>